﻿Public Class Customer
    Private m_Name As String
    Public Property Name() As String
        Get
            Return m_Name
        End Get
        Set(ByVal value As String)
            m_Name = value
        End Set
    End Property


    Private m_Orders As New List(Of SalesOrder)
    Public Property Orders() As List(Of SalesOrder)
        Get
            Return m_Orders
        End Get
        Set(ByVal value As List(Of SalesOrder))
            m_Orders = value
        End Set
    End Property
End Class
Public Class SalesOrder
    Implements System.ComponentModel.IDataErrorInfo

    Private m_Description As String
    Public Property Description() As String
        Get
            Return m_Description
        End Get
        Set(ByVal value As String)
            m_Description = value
        End Set
    End Property


    Private m_Quantity As Integer
    Public Property Quantity() As Integer
        Get
            Return m_Quantity
        End Get
        Set(ByVal value As Integer)
            m_Quantity = value
        End Set
    End Property


    Private m_DateOrdered As Date
    Public Property DateOrdered() As Date
        Get
            Return m_DateOrdered
        End Get
        Set(ByVal value As Date)
            m_DateOrdered = value
        End Set
    End Property

    Public ReadOnly Property ErrorSummary() As String _
                              Implements System.ComponentModel.IDataErrorInfo.Error
        Get
            Dim summary As New System.Text.StringBuilder
            Dim err As String = ErrorItem("Description")
            If Not err = "" Then summary.AppendLine(err)
            err = ErrorItem("Quantity")
            If Not err = "" Then summary.AppendLine(err)
            err = ErrorItem("DateOrdered")
            If Not err = "" Then summary.AppendLine(err)
            Return summary.ToString
        End Get
    End Property

    Default Public ReadOnly Property ErrorItem(ByVal columnName As String) _
                     As String Implements System.ComponentModel.IDataErrorInfo.Item
        Get
            Select Case columnName
                Case "Description"
                    If Me.m_Description = "" Then _
                          Return "Need to order item description"
                Case "Quantity"
                    If Me.m_Quantity <= 0 Then _
                          Return "Need to supply quantity of order"
                Case "DateOrdered"
                    If Me.m_DateOrdered > Now Then _
                          Return "Need to specify a date in the past"
            End Select
            Return ""
        End Get
    End Property
End Class
